package com.vpclub.service;

import com.vpclub.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : leimingchao
 * @Description:
 * @date Date : 2021年06月07日 22:12
 */
@Service
public class BookService {
    @Autowired
    private BookDao bookDao;


    public void checkOut(String username, String isbn) {
        //1.减库存
        bookDao.updateStock(isbn);
        int price = bookDao.getPrice(isbn);
        //2.减余额
        bookDao.updateBalance(username, price);

        int i = 10 / 0;

    }


    public void updatePrice(String isbn, int price) {
        bookDao.updatePrice(isbn, price);
        // int i = 10 / 0;
    }

    /**
     * 根据业务的特性，进行调整
     *
     * @param isbn
     * @return
     */
    public int getPrice(String isbn) {
        int price = bookDao.getPrice(isbn);
        return price;
    }

    public void mulTX() {
        checkOut("Tom", "ISBN-001");
        updatePrice("ISBN-002", 998);
        int i = 10 /0;
    }
}
